home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
term.exe
/
TERM.H
< prev
Wrap
C/C++ Source or Header
|
1992-01-07
|
4KB
|
137 lines
// Author: Patrick Reilly
// ID: 70274,161 (Compuserve)
// Version 1.01
// Contents --------------------------------------------------------------
//
// KeyMap
// termbuf
//
// Description
//
// Defines the typedef KeyMap, used to map keycodes to terminal
// emulation strings. Defines the class termbuf, a streambuf-derived
// class that allows stream-based terminal emulation for use in tele-
// communication programs.
//
// End -------------------------------------------------------------------
// Interface Dependencies ------------------------------------------------
#ifndef __TERM_H
#define __TERM_H
#ifndef __IOSTREAM_H
#include <iostream.h>
#endif
#ifndef __CONIO_H
#include <conio.h>
#endif
// End Interface Dependencies --------------------------------------------
// Macros //
#define MAXKEYMAPSIZE 243
// NOTE:
//
// MAXKEYMAPSIZE is the largest number of entries in a KeyMap. This
// number is WRONG! 243 was determined experimentally on a laptop computer
// and is the number of responses (non-duplicate) that I got from a
// laptop computer using library call bioskey(0). In later upgrades I'll
// change this number to actively reflect the true number. An alternative
// is to dynamically allocate mapMatch[], since this is what this macro
// is used for. This means a bit more error checking though. Of course in
// use, this macro only needs to be large enough to hold the largest size
// KeyMap array you're going to use.
// Typedef structure //
typedef struct
{
unsigned int keycode; // keycode - returned by bioskey(0).
char _FAR *string; // emulation string.
} KeyMap;
// Description -----------------------------------------------------------
//
// KeyMap typedef is used to store key mapping information. The member
// keycode is a keyboard keystroke as returned by the bioskey(0) library
// function. The most significant byte is the key scan code, the least
// significant byte is the ascii code. The member string is an asciiz
// string containing the characters that emulate the required terminal.
//
// End -------------------------------------------------------------------
// Typedef structure //
typedef struct
{
int left,top,right,bottom;
} Rect;
// Description -----------------------------------------------------------
//
// Typedef structure Rect is used to maintain a rectangular screen
// coordinate.
//
// End -------------------------------------------------------------------
// Class //
class _CLASSTYPE termbuf : public streambuf
{
public:
// Constructors //
_Cdecl termbuf();
_Cdecl termbuf(char _FAR *,int);
// Destructor //
_Cdecl ~termbuf();
// overloaded member from streambuf //
streambuf _FAR * _Cdecl setbuf(signed char _FAR *,int);
// extraction method //
int _Cdecl underflow();
// insertion method //
int _Cdecl overflow(int=EOF);
// key mapping method //
void _Cdecl setmap(KeyMap _FAR *);
// console methods //
void _Cdecl setWindow(Rect&);
void _Cdecl setWindow(int,int,int,int);
void _Cdecl setBackground(int);
void _Cdecl setForeground(int);
void _Cdecl setAttribute(int);
void _Cdecl clearWindow();
void _Cdecl gotoWindow(int,int);
protected:
// console methods //
void _Cdecl initScreen();
virtual void _Cdecl processKey(unsigned int);
KeyMap _FAR *map,_FAR *emap;
struct text_info ti;
int insLen,keymapsize;
char noMap,mapMatch[MAXKEYMAPSIZE];
};
// Description -----------------------------------------------------------
//
// Class termbuf is a streambuf-derived class for use with streams
// that function as terminals. Can be used with class istream (reads the
// keyboard and converts into terminal emulation strings), class ostream
// (accepts terminal emulation strings and displays to the console), or
// with class iostream (acts as both).
//
// End -------------------------------------------------------------------
#endif // __TERM_H